package com.gopay.scheduler.service.eventshandler.impl;

import java.util.List;
import java.util.concurrent.CountDownLatch;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gopay.common.domain.report.Event;
import com.gopay.common.event.EventBus;

public class EventPublishTask implements Runnable {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private EventBus eventBus;
    private List<Event> eventList;
    private CountDownLatch latch;

    public EventPublishTask(EventBus eventBus, List<Event> eventList, CountDownLatch latch) {
        this.eventBus = eventBus;
        this.eventList = eventList;
        this.latch = latch;
    }

    @Override
    public void run() {
        try {
            for (Event event : eventList) {
                eventBus.publish(event);
            }
        } catch (Exception e) {
            logger.info("----------eventBus.publish error---------", e);
        } finally {
            latch.countDown();
        }

    }

}
